package org.raymond.icloud.modules.dp.composite.router;

import org.assertj.core.util.Lists;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collector;
import java.util.stream.Collectors;

/**
 * @author raymond
 * @version V1.0
 * @Description: TODO
 */
public class RouterClient {
    public static void exec(String[] args){
        Storage center = new Storage();
        center.setName("中心库");
        center.setId(0);

        Storage a1 = new Storage();
        a1.setName("1级库1");
        a1.setId(1);

        Storage a2 = new Storage();
        a2.setName("1级库2");
        a2.setId(2);

        Storage a3 = new Storage();
        a3.setName("1级库3");
        a3.setId(3);

        Storage a4 = new Storage();
        a4.setName("1级库4");
        a4.setId(4);

        Storage b1 = new Storage();
        b1.setName("2级库1");
        b1.setId(21);

        Storage b2 = new Storage();
        b2.setName("2级库2");
        b2.setId(22);

        Storage b3 = new Storage();
        b3.setName("2级库3");
        b3.setId(23);

        Storage b4 = new Storage();
        b4.setName("2级库4");
        b4.setId(24);

        Storage b5 = new Storage();
        b5.setName("2级库5");
        b5.setId(25);

        Storage b6 = new Storage();
        b6.setName("2级库6");
        b6.setId(26);

        Storage b7 = new Storage();
        b7.setName("2级库7");
        b7.setId(27);

        Storage b8 = new Storage();
        b8.setName("2级库8");
        b8.setId(28);

        Route a1Route = new Route();
        a1Route.setLeftId(0);
        a1Route.setRightId(1);

        Route a2Route = new Route();
        a2Route.setLeftId(0);
        a2Route.setRightId(2);

        Route a3Route = new Route();
        a3Route.setLeftId(0);
        a3Route.setRightId(3);

        Route a4Route = new Route();
        a4Route.setLeftId(0);
        a4Route.setRightId(4);

        Route b1Route = new Route();
        b1Route.setLeftId(1);
        b1Route.setRightId(21);

        Route b2Route = new Route();
        b2Route.setLeftId(1);
        b2Route.setRightId(22);

        Route b3Route = new Route();
        b3Route.setLeftId(1);
        b3Route.setRightId(23);

        Route b4Route = new Route();
        b4Route.setLeftId(1);
        b4Route.setRightId(24);

        Route b5Route = new Route();
        b5Route.setLeftId(2);
        b5Route.setRightId(21);

        Route b6Route = new Route();
        b6Route.setLeftId(2);
        b6Route.setRightId(22);

        Route b7Route = new Route();
        b7Route.setLeftId(2);
        b7Route.setRightId(23);

        Route b8Route = new Route();
        b8Route.setLeftId(3);
        b8Route.setRightId(25);

        Route b9Route = new Route();
        b9Route.setLeftId(3);
        b9Route.setRightId(26);

        Route b10Route = new Route();
        b10Route.setLeftId(3);
        b10Route.setRightId(27);

        List<Storage> storageList = Lists.newArrayList(center,a1,a2,a3,a4,b1,b2,b3,b4,b5,b6,b7,b8);
        Map<Integer,Storage> storageMap = storageList.stream().collect(Collectors.toMap(Storage::getId, v->v));
        List<Route> routeList = Lists.newArrayList(a1Route,a2Route,a3Route,a4Route,b1Route,b2Route,b3Route,b4Route,b5Route,b6Route,b7Route);
        Map<Integer,List<Route>> leftListMap= routeList.stream().collect(Collectors.groupingBy(Route::getLeftId));
        Map<Integer,List<Route>> rightListMap = routeList.stream().collect(Collectors.groupingBy(Route::getRightId));

        Integer inputRightId = 27;
        // 查找rightId=x的routeList
        List<Route> rightRouteList = rightListMap.get(inputRightId);
        Set<Integer> leftIdsInRightRoute = rightRouteList.stream().map(Route::getLeftId).collect(Collectors.toSet());
        List<Route> leftRouteList = routeList.stream().filter(r->leftIdsInRightRoute.contains(r.getLeftId())).collect(Collectors.toList());
    }

    public void tree(List<Route> routeList){

    }
}
